define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'car/index' + location.search,
                    add_url: 'car/add',
                    edit_url: 'car/edit',
                    del_url: 'car/del',
                    multi_url: 'car/multi',
                    table: 'car',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.nickname', title: __('User_id')},
                        {field: 'name', title: __('Name')},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'images', title: __('Images'), events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'gearbox', title: __('Gearbox'), searchList: {"manual":__('Gearbox manual'),"automatic":__('Gearbox automatic'),"Hand_in_one":__('Gearbox hand_in_one'),"Dual_clutch":__('Gearbox dual_clutch'),"CVT_continuously_variable":__('Gearbox cvt_continuously_variable'),"Seven_speed_dual_clutch":__('Gearbox seven_speed_dual_clutch')}, formatter: Table.api.formatter.normal},
                        {field: 'show_mileage', title: __('Show_mileage')},
                        {field: 'car_displacement', title: __('Car_displacement'), operate:'BETWEEN'},
                        {field: 'Registration_time', title: __('Registration_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'Compulsory_insurance_due_time', title: __('Compulsory_insurance_due_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'Inspection_due_time', title: __('Inspection_due_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'color', title: __('Color'), searchList: {"black":__('Color black'),"white":__('Color white'),"red":__('Color red'),"blue":__('Color blue'),"grey":__('Color grey'),"green":__('Color green'),"yellow":__('Color yellow'),"silver":__('Color silver'),"orange":__('Color orange'),"golden":__('Color golden'),"purple":__('Color purple'),"Champagne_gold":__('Color champagne_gold'),"brown":__('Color brown'),"other":__('Color other')}, formatter: Table.api.formatter.normal},
                        {field: 'vehicle_type', title: __('Vehicle_type'), searchList: {"car":__('Vehicle_type car'),"SUV":__('Vehicle_type suv'),"MPV":__('Vehicle_type mpv'),"Dual_clutch":__('Vehicle_type dual_clutch'),"CVT_continuously_variable":__('Vehicle_type cvt_continuously_variable'),"Seven_speed_dual_clutch":__('Vehicle_type seven_speed_dual_clutch')}, formatter: Table.api.formatter.normal},
                        {field: 'city', title: __('City')},
                        {field: 'brand_id', title: __('Brand_id')},
                        {field: 'country', title: __('Country'), searchList: {"china":__('Country china'),"german":__('Country german'),"european":__('Country european'),"japanese":__('Country japanese'),"france":__('Country france'),"america":__('Country america'),"korean":__('Country korean')}, formatter: Table.api.formatter.normal},
                        {field: 'car_age', title: __('Car_age'), operate:'BETWEEN'},
                        {field: 'phone', title: __('Phone')},
                        {field: 'content', title: __('Content')},
                        {field: 'weigh', title: __('Weigh')},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3')}, formatter: Table.api.formatter.status},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});